const express = require('express');
const router = express.Router();
const GoodsController = require('../controllers/goodsController');

/**
 * @swagger
 * tags:
 *   name: Goods
 *   description: 货物管理
 */

/**
 * @swagger
 * /api/goods:
 *   get:
 *     summary: 获取所有货物
 *     tags: [Goods]
 *     responses:
 *       200:
 *         description: 成功获取货物列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   type: array
 *                   items:
 *                     $ref: '#/components/schemas/Goods'
 *       500:
 *         description: 服务器错误
 */
router.get('/', GoodsController.getAllGoods);

/**
 * @swagger
 * /api/goods/export/overview:
 *   get:
 *     summary: 导出库存总览为Excel
 *     tags: [Goods]
 *     responses:
 *       200:
 *         description: 成功导出Excel文件
 *         content:
 *           application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:
 *             schema:
 *               type: string
 *               format: binary
 *       500:
 *         description: 服务器错误
 */
router.get('/export/overview', GoodsController.exportInventoryOverviewToExcel);

/**
 * @swagger
 * /api/goods/export/details:
 *   get:
 *     summary: 导出库存明细为Excel
 *     tags: [Goods]
 *     responses:
 *       200:
 *         description: 成功导出Excel文件
 *         content:
 *           application/vnd.openxmlformats-officedocument.spreadsheetml.sheet:
 *             schema:
 *               type: string
 *               format: binary
 *       500:
 *         description: 服务器错误
 */
router.get('/export/details', GoodsController.exportInventoryDetailsToExcel);

/**
 * @swagger
 * /api/goods/{id}:
 *   get:
 *     summary: 根据ID获取货物
 *     tags: [Goods]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 货物ID
 *     responses:
 *       200:
 *         description: 成功获取货物
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 data:
 *                   $ref: '#/components/schemas/Goods'
 *       404:
 *         description: 货物未找到
 *       500:
 *         description: 服务器错误
 */
router.get('/:id', GoodsController.getGoodsById);

/**
 * @swagger
 * /api/goods:
 *   post:
 *     summary: 创建新货物
 *     tags: [Goods]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             required:
 *               - name
 *               - sku
 *             properties:
 *               name:
 *                 type: string
 *                 description: 货物名称
 *               sku:
 *                 type: string
 *                 description: SKU编码
 *               quantity:
 *                 type: integer
 *                 description: 数量
 *               location:
 *                 type: string
 *                 description: 货位
 *               status:
 *                 type: string
 *                 description: 状态
 *               batch_number:
 *                 type: string
 *                 description: 批次号
 *               expiry_date:
 *                 type: string
 *                 format: date
 *                 description: 过期日期
 *               specification:
 *                 type: string
 *                 description: 规格
 *               unit:
 *                 type: string
 *                 description: 单位
 *     responses:
 *       201:
 *         description: 货物创建成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *                 data:
 *                   $ref: '#/components/schemas/Goods'
 *       400:
 *         description: 请求参数错误
 *       500:
 *         description: 服务器错误
 */
router.post('/', GoodsController.createGoods);

/**
 * @swagger
 * /api/goods/{id}:
 *   put:
 *     summary: 更新货物信息
 *     tags: [Goods]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 货物ID
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               name:
 *                 type: string
 *                 description: 货物名称
 *               sku:
 *                 type: string
 *                 description: SKU编码
 *               quantity:
 *                 type: integer
 *                 description: 数量
 *               location:
 *                 type: string
 *                 description: 货位
 *               status:
 *                 type: string
 *                 description: 状态
 *               batch_number:
 *                 type: string
 *                 description: 批次号
 *               expiry_date:
 *                 type: string
 *                 format: date
 *                 description: 过期日期
 *               specification:
 *                 type: string
 *                 description: 规格
 *               unit:
 *                 type: string
 *                 description: 单位
 *     responses:
 *       200:
 *         description: 货物更新成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *                 data:
 *                   $ref: '#/components/schemas/Goods'
 *       400:
 *         description: 请求参数错误
 *       404:
 *         description: 货物未找到
 *       500:
 *         description: 服务器错误
 */
router.put('/:id', GoodsController.updateGoods);

/**
 * @swagger
 * /api/goods/{id}:
 *   delete:
 *     summary: 删除货物
 *     tags: [Goods]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 货物ID
 *     responses:
 *       200:
 *         description: 货物删除成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 success:
 *                   type: boolean
 *                 message:
 *                   type: string
 *       404:
 *         description: 货物未找到
 *       500:
 *         description: 服务器错误
 */
router.delete('/:id', GoodsController.deleteGoods);

module.exports = router;